Fix asset loading for GitHub Pages deployment - images and videos now load correctly #62
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When deployed to GitHub Pages, the website was not loading any images or videos due to incorrect asset path handling. GitHub Pages serves project repositories under a
/web-novitbase path, but the application was not properly accounting for this in asset references.Problem
The original issue manifested as:
Root Cause
The problem had multiple components:
Static assets in
/publicweren't being moved to the correct GitHub Pages structure - the post-build script was only moving locale directories and Next.js bundles, but leaving root-level assets like logos and favicons at the wrong path.Asset path function was inconsistent - the
getAssetPathfunction wasn't properly adding the/web-novitbase path for GitHub Pages builds.Navigation links were incorrectly using asset path logic - components were using
getAssetPathfor navigation hrefs, causing double base path application.Solution
1. Enhanced Post-build Script
Updated
scripts/post-build.jsto properly copy root-level assets:2. Fixed Asset Path Logic
Corrected
getAssetPathinsrc/config/constants.tsto properly detect GitHub Pages environment and add base path:3. Separated Navigation and Asset Paths
Created
getNavigationPathfunction to handle navigation links separately from static assets, preventing double base path application.4. Updated Components
Modified all components to use the appropriate function:
getAssetPath()for images, videos, logos, faviconsgetNavigationPath()for navigation hrefs and internal linksResult
All assets now load correctly in both environments:
http://localhost:3000/images/logo.pnghttp://novitsoftware.github.io/web-novit/images/logo.pngThe website is now fully functional on GitHub Pages with all images and videos loading properly.
Fixes #61.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.